package com.itheima.health.controller;


import com.itheima.health.resource.entity.Result;
import com.itheima.health.resource.pub.MessageConstant;
import com.itheima.health.service.SetmealService;
import com.itheima.pojo.Setmeal;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *   微信端的后台 业务处理
 */
@RestController
@RequestMapping("setmeal")
public class SetmealController {


    @Reference
    private SetmealService setmealService;



    @RequestMapping("findAllSetmeal.do")
    public  Result  findAllSetmeal(){
        try {
            List<Setmeal> list = setmealService.findAllSetmeal();
            return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @RequestMapping("findSetMealDetail.do")
    public  Result  findSetMealDetail(@RequestParam("id")  Integer id){
        try {
            Setmeal  setmeal = setmealService.findSetMealDetailBySetmealId(id);
            return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @RequestMapping("findSetmealById.do")
    public  Result  findSetmealById(@RequestParam("id")  Integer id){
        try {
            Setmeal  setmeal = setmealService.findSetmealById(id);
            return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
